package com.online.teaching.dao;
import com.online.teaching.pojo.Homework;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/****
 * @Author:admin
 * @Description:Homework的Dao
 * @Date 2019/6/14 0:12
 *****/
public interface HomeworkMapper extends Mapper<Homework> {
    /**
     * 老师删除作业
     * @param id
     * @return
     */
    @Update("UPDATE homework SET is_valid=-1 WHERE homework_id=#{homework_id}")
    int deleteHomework(@Param("homework_id") Integer id);

    /**
     * 老师查询其已经布置作业的列表
     * @param teacherId
     * @return
     */
    @Select("SELECT * FROM homework WHERE teaches_id =#{teaches_id}")
    List<Homework> teacherGetHomeWorkList(@Param("teacher_id") Integer teacherId);

    /**
     * 根据作业id查出该作业对应的老师的id
     * @param homeWorkId
     * @return
     */
    @Select("SELECT teaches_id FROM teaches WHERE teaches_id=(SELECT teaches_id FROM homework WHERE homework_id = 1)")
    Integer getTeacherId(@Param("homework_id") Integer homeWorkId);
}
